﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Watcher.AMQ;
using Watcher.Matrix;
using Watcher.AMQ.Objects;
using AsyncBindingList;
using Watcher.Presentation.Visualization;

namespace Watcher
{
    delegate void UpdateGridDelegate();
    public partial class Form1 : Form
    {
        private List<Thread> threads = new List<Thread>();
        public Form1()
        {
            InitializeComponent();

            


        }

        private void grabQueueButton_Click(object sender, EventArgs e)
        {
            ThreadStat.Text += "Starting new plot...\n";
            
            ThreadStart Run = new ThreadStart(RunPlot);
            threads.Add(new Thread(Run));
            Thread ThreadStart = threads.Last<Thread>();
            ThreadStart.Start();
            ThreadStat.Text += "Done\n";
        }

        static void RunPlot()
        {
            using (PlotEngine game = new PlotEngine())
            {

                game.Keyboard.KeyUp += delegate(object sender, OpenTK.Input.KeyboardKeyEventArgs e)
                {
                    if (e.Key == OpenTK.Input.Key.F11)
                    {
                        if (game.WindowState == OpenTK.WindowState.Fullscreen)
                            game.WindowState = OpenTK.WindowState.Normal;
                        else
                            game.WindowState = OpenTK.WindowState.Fullscreen;
                    }
                };
                game.Run(30.0);
            }
        }

        private void StopAll_Click(object sender, EventArgs e)
        {
            ThreadStat.Text += "Stopping all threads...\n";
            
            foreach (Thread t in threads)
                t.Abort();

            ThreadStat.Text += "Done!\n";
        }
    }
}
